<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>点击焦点换图</title>
    <link rel="stylesheet" href="css/style.css">
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
</head>

<body>
    <div class="content">
        <div id="list">
            <img src="images/01.png" alt="">
            <img src="images/02.png" alt="">
            <img src="images/03.png" alt="">
            <img src="images/04.png" alt="">
            <img src="images/05.png" alt="">
        </div>
        <button id="prev"></button>
        <button id="next"></button>
        <div id="btns">
            <span class="current"></span>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
        </div>
    </div>
    <script>
        $(function () {
            var index = 0;
            $("#next").click(function () {
                index++;
                if (index > 4) {
                    index = 0;
                }
                animate(index);
            })
            $("#prev").click(function () {
                index--;
                console.log(index);
                if (index < 0) {
                    index = 4;
                }
                animate(index);
            })
            function animate(index) {
                $("#list img").eq(index).fadeIn(500).siblings().fadeOut(500);
                $("#btns span").eq(index).addClass("current").siblings().removeClass("current");
            }
            $("#btns span").click(function(){
                $(this).addClass("current").siblings().removeClass("current");
                index = $(this).index();
                $("#list img").eq(index).fadeIn(500).siblings().fadeOut(500);
                
            })
        })
    </script>
</body>
</html>